﻿#include "FITKAcousticsFEModelAdaptor.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsFEModel.h"
#include "FITK_Component/FITKAcousticsModel/FITKAbstractFESubSys.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsFEFace.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsSensors.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsFENodeMap.h"
#include "FITKAcousticsFESubSysElementListAdaptor.h"
#include "FITKAcousticsFESubSysMgrAdaptor.h"

bool IO::FITKAcousticsFEModelAdaptor::adaptR()
{
    Acoustics::FITKAcousticsFEModel* FEModelP =
        dynamic_cast<Acoustics::FITKAcousticsFEModel*>(_dataObj);
    if (FEModelP == nullptr) return false;

    Acoustics::FITKAcousticsFESubSysElementList*FESubSysElementListP = FEModelP->getFESubSysElementList();//单元列表
    Acoustics::FITKAcousticsFESubSysManager*FESubSysManagerP = FEModelP->getFESubSysManager();            //子系统管理器
    bool FESubSysElementListRet = false;
    bool FESubSysMgrAdaptor = false;

    if (FESubSysElementListP != nullptr)
    {
        //单元列表适配器
        FITKAcousticsFESubSysElementListAdaptor* adaptor =
            FITKIOADAPTORFACTORY->createT<FITKAcousticsFESubSysElementListAdaptor>("FITKAcousticsHDF5", "Acoustics::FITKAcousticsFESubSysElementList");
        if (adaptor == nullptr) return false;
        adaptor->setReader(_reader);
        adaptor->setData(FESubSysElementListP);
        FESubSysElementListRet = adaptor->adaptR();
        delete adaptor;
    }
    if (FESubSysManagerP != nullptr)
    {
        //子系统管理器适配器
        FITKAcousticsFESubSysMgrAdaptor* adaptor =
            FITKIOADAPTORFACTORY->createT<FITKAcousticsFESubSysMgrAdaptor>("FITKAcousticsHDF5", FESubSysManagerP);
        if (adaptor == nullptr) return false;
        adaptor->setReader(_reader);
        adaptor->setDataObject(FESubSysManagerP);
        FESubSysMgrAdaptor = adaptor->adaptR();
        delete adaptor;
    }
    return FESubSysElementListRet && FESubSysMgrAdaptor;
}

bool IO::FITKAcousticsFEModelAdaptor::adaptW()
{
    Acoustics::FITKAcousticsFEModel* FEModelP =
        dynamic_cast<Acoustics::FITKAcousticsFEModel*>(_dataObj);
    if (FEModelP == nullptr) return false;

    Acoustics::FITKAcousticsFESubSysElementList*FESubSysElementListP = FEModelP->getFESubSysElementList();//单元列表
    Acoustics::FITKAcousticsFESubSysManager*FESubSysManagerP = FEModelP->getFESubSysManager();            //子系统管理器
    Acoustics::FITKAcousticsFEFaceManager*FEFaceManagerP = FEModelP->getFEFaceManager();                  //面管理器
    Acoustics::FITKAcousticsSensorsManager*SensorManagerP = FEModelP->getSensorManager();                 //传感器管理器
    Acoustics::FITKAcousticsFENodeMapManager* NodesMapManagerP = FEModelP->getNodesMapManager();          //节点映射管理器--先不写

    bool FESubSysElementListRet = false;
    bool FESubSysMgrAdaptor = false;

    if (FESubSysElementListP != nullptr)
    {
        //单元列表适配器
        FITKAcousticsFESubSysElementListAdaptor* adaptor =
            FITKIOADAPTORFACTORY->createT<FITKAcousticsFESubSysElementListAdaptor>("FITKAcousticsHDF5", "Acoustics::FITKAcousticsFESubSysElementList");
        if (adaptor == nullptr) return false;
        adaptor->setWriter(_writer);
        adaptor->setData(FESubSysElementListP);
        FESubSysElementListRet = adaptor->adaptW();
        delete adaptor;
    }
    if (FESubSysManagerP != nullptr)
    {
        FITKAcousticsFESubSysMgrAdaptor* adaptor =
            FITKIOADAPTORFACTORY->createT<FITKAcousticsFESubSysMgrAdaptor>("FITKAcousticsHDF5", FESubSysManagerP);//子系统管理器
        if (adaptor)
        {
            adaptor->setWriter(_writer);
            adaptor->setDataObject(FESubSysManagerP);
            FESubSysMgrAdaptor = adaptor->adaptW();
            delete adaptor;
        }
    }

    


    return FESubSysElementListRet&& FESubSysMgrAdaptor;
}
